<?php
namespace Home\Controller;
use Think\Controller;
class ProfileController extends BaseController {



    public function index(){
    	//$this->model=D('users');
    	 $data=session('users');
    	$this->assign('one',$data);


    	//$this->model=D('users');
        //$id = I('get.id');
        //dump($id);exit;//调试
        //$this->model=M('user');
        //$one = $this->model->find($id);
        //dump($one);exit;
        //$this->assign('one',$one);

        $this->display();

}
  

public function changepassword(){

	    $data=I('post.');
		$this->model=D('users');
		$users=session('users');
	//	$mm=M('users')->where("ydq_username='".$data['ydq_username']."'")->select();

//dump($data['old']);
//dump($users['ydq_pass']);
		if(strcmp($users['ydq_pass'],$data['old'])!=0){

			$this->error('修改失败，原密码不正确');
    }
    elseif (strcmp($users[$new1],$data[$new2])!=0) {

	  $this->error('修改失败，新密码和确认密码不一致');
    }
    else{
	    
	    $users['ydq_pass']=$data['new2'];
    	$list=$users;
    	//dump($this->model->create($list));exit;
	    if($this->model->create($list)){
	    $this->model->save();//必须有id
	    session('ydq_pass',$data['new2']);
    	$this->success('密码修改成功！',U('Profile/index'));
    
	    }
	    else{
		$this->error('修改失败');
	    }
        }
	}


	public function changeinfor(){

         $data = I('post.');
        //$data['hobby']=implode(',', $data['hobby']);
         $data=session('users');
        $this->assign('users',$data); 

        //dump($data);exit;
       $this->model=M('users');
           if(!empty($_FILES['ydq_photo']['name'])){
         /*   $photo=$this->model->where ('id'=.$data['ydq_id'])->getField('ydq_photo');
            if(is_file(filename)){
                unlink();
            }
            if (is_file(filename)) {
                unlink();
                # code...
            }*/
            $data['ydq_photo']=$this->uploadfile('ydq_photo');
        }
        if($this->model->create($data)){
            $this->model->save();//用save必须有id 
            $this->success('更新成功！',U('Profile/index'));
            
        }
        else{
            $this->error('更新失败！');

        }
	}

    public function myclub(){
        $this->model=D('members');
        $user=session('users');
        //dump($user);exit;
        $this->assign('one',$user);
        $group=$this->model->relation(true)->where('ydq_stunum='.$user['ydq_stunum'])->select();
        $this->assign('myclub',$group);

       $club=D('groups')->where('ydq_leader='.$user['ydq_stunum'])->select();
        $this->assign('club',$club);
       // dump($user);exit;
        $this->display();
    }


    public function mypractices(){
        $this->model=D('stuprac');
        $user=session('users');
        //dump($user);exit;
        $this->assign('one',$user);
        $practices=$this->model->relation(true)->where('ydq_stunum='.$user['ydq_stunum'])->select();
        $this->assign('mypractices',$practices);

        $myact=D('practices')->where('ydq_stunum='.$user['ydq_stunum'])->select();
        $this->assign('myact',$myact);
       // dump($user);exit;
        $this->display();
    }

       public function form(){
       //test();
    //  $this->display();
        parent::form($this->tbl);  
    }


public function add(){
      $data = I('post.');
       // dump($_FILES);
        $data['ydq_logo']=$this->uploadfile('ydq_logo');
     //  dump($data);exit;
        //
        //$data['whr_username']='';
        //$data['whr_username']=I['post.username'];伪装
        $this->model = D('groups');
        //dump($this->model);exit;//D方法做验证
        if ($this->model->create($data)) {
            $this->model->add();
            $this->success('创建成功！',U('profile/index'));
        }else{
            $this->error('创建失败！'.$this->model->getError());
          //  parent::add($this->tbl,'ydq_logo');
        }
    



}
 public function form1(){
       //test();
    //  $this->display();
       $data=session('user');
        $this->assign('one',$data); 
        $this->assign('atlist',M('groups')->select());
        parent::form($this->tbl);
       
    }

      public function add1(){
        $data = I('post.');
       // dump($_FILES);
        $data['ydq_pfile']=$this->uploadfilee('ydq_pfile');
     //  dump($data);exit;
        //
        //$data['whr_username']='';
        //$data['whr_username']=I['post.username'];伪装
        $this->model = D('practices');
        //dump($this->model);exit;//D方法做验证
        if ($this->model->create($data)) {
            $this->model->add();
            $this->success('创建成功！',U('profile/index'));
        }else{
            $this->error('创建失败！'.$this->model->getError());
          //  parent::add($this->tbl,'ydq_logo');
        }
    

}



}